package com.qing.eduservice.task;

import com.qing.eduservice.service.StatisticsDailyService;
import org.apache.poi.ss.usermodel.DateUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @ClassName Yjx
 * @Description TODO
 * @date 2022/9/19 14:54
 * @Version 1.0
 */
@Component
public class ScheduledTask {

    private final StatisticsDailyService dailyService;

    public ScheduledTask(StatisticsDailyService dailyService) {
        this.dailyService = dailyService;
    }

    @Scheduled(cron = "0/5 * * * * ?")
    public void task1() {
        System.out.println("*********++++++++++++*****执行了");
    }

    /**
     * 每天凌晨1点执行定时
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void task2() {
        //获取上一天的日期
        String day = LocalDateTime.now().toLocalDate().minusDays(1).toString();
        dailyService.createStatisticsByDay(day);
    }

}
